package com.ponhu.ea2.goodsCenter.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ponhu.ea2.entity.OperationRecordLogs;
import com.ponhu.ea2.goodsCenter.provider.service.OperationRecordLogsService;
import com.ponhu.ea2.goodsCenter.provider.mapper.OperationRecordLogsMapper;
import com.ponhu.ea2.query.OperationRecordLogsQuery;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OperationRecordLogsServiceImpl
        extends ServiceImpl<OperationRecordLogsMapper, OperationRecordLogs>
        implements OperationRecordLogsService {

    /**
     * 分页查询操作记录日志列表
     *
     * @param operationRecordLogsQuery
     * @return
     */
    @Override
    public IPage<OperationRecordLogs> getOperationRecordLogsPage(OperationRecordLogsQuery operationRecordLogsQuery) {
        IPage<OperationRecordLogs> page = new Page<>();
        page.setSize(operationRecordLogsQuery.getPageSize());
        page.setCurrent(operationRecordLogsQuery.getPageIndex());

        return this.page(page, Wrappers.lambdaQuery(OperationRecordLogs.class)
                .eq(OperationRecordLogs::getBusinessTable, operationRecordLogsQuery.getBusinessTable())
                .eq(OperationRecordLogs::getRecordId, operationRecordLogsQuery.getRecordId())
                .orderByDesc(OperationRecordLogs::getCreateTime));
    }

    @Override
    public List<OperationRecordLogs> getAllLogsByRecordId(Long recordId) {
        LambdaQueryWrapper<OperationRecordLogs> queryWrapper = Wrappers
                .lambdaQuery(OperationRecordLogs.class)
                .eq(OperationRecordLogs::getRecordId, recordId);

        return list(queryWrapper);
    }

}




